/*
{
"状态":1,
"名称":"复制-用户角色信息",
"作者":"马学兵",
"创建时间":"2018-09-01",
"功能":"复制-用户角色信息",
"log": [
	{"date":"06-01" , "dev" :"hzhh" , "content" : "append取值  1追加,0覆盖"}
]
}
*/


DECLARE @uers VARCHAR(4000)
DECLARE @userkey INT
DECLARE @append CHAR(1)=''

set @uers='{uers}'
set @userkey='{userkey}'
set @append='{append}'

IF @append='0'
BEGIN
	if @userkey=4
	begin
			RAISERROR ('SQL:管理员权限不允许覆盖', 16 ,1 ) ; 
		return 
	end 
	DELETE FROM y_role_user WHERE user_key=@userkey
END 

INSERT INTO y_role_user(user_key,role_key,create_time,update_time)
SELECT @userkey,A.role_key,GETDATE(),GETDATE() FROM 
(
	SELECT DISTINCT role_key FROM dbo.y_role_user WHERE user_key IN (SELECT CONVERT(INT,value) FROM dbo.Ft_Split(@uers,','))
) A LEFT JOIN y_role_user B ON B.user_key=@userkey AND B.role_key = A.role_key
WHERE B.user_key IS NULL 


